home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / disk / RCS / diskIO.c,v < prev    next >
Encoding:
Text File  |  1992-12-10  |  20.0 KB  |  776 lines

  1. head     1.10;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    eklee:1.10; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.10
  10. date     91.12.16.19.29.55;  author voelker;  state Exp;
  11. branches ;
  12. next     1.9;
  13.  
  14. 1.9
  15. date     91.09.14.15.17.12;  author mendel;  state Exp;
  16. branches ;
  17. next     1.8;
  18.  
  19. 1.8
  20. date     90.03.16.17.41.15;  author jhh;  state Exp;
  21. branches ;
  22. next     1.7;
  23.  
  24. 1.7
  25. date     90.01.31.13.59.59;  author shirriff;  state Exp;
  26. branches ;
  27. next     1.6;
  28.  
  29. 1.6
  30. date     89.10.02.23.17.57;  author jhh;  state Exp;
  31. branches ;
  32. next     1.5;
  33.  
  34. 1.5
  35. date     89.09.25.12.32.35;  author jhh;  state Exp;
  36. branches ;
  37. next     1.4;
  38.  
  39. 1.4
  40. date     88.12.05.14.23.13;  author nelson;  state Exp;
  41. branches ;
  42. next     1.3;
  43.  
  44. 1.3
  45. date     88.10.27.15.30.47;  author nelson;  state Exp;
  46. branches ;
  47. next     1.2;
  48.  
  49. 1.2
  50. date     88.07.19.11.54.30;  author douglis;  state Exp;
  51. branches ;
  52. next     1.1;
  53.  
  54. 1.1
  55. date     88.06.02.12.54.09;  author brent;  state Exp;
  56. branches ;
  57. next     ;
  58.  
  59.  
  60. desc
  61. @Sector and block aligned I/O to a raw disk.
  62. @
  63.  
  64.  
  65. 1.10
  66. log
  67. @removed printf()s that reported short reads and writes it
  68. Disk_SectorRead/Write...let callers decide to report the error
  69.  
  70. If the procedures return an error, then the streams can be tested
  71. for EOF or the errno can be checked to see if there was a system
  72. call error or a short read/write
  73.  
  74. @
  75. text
  76. @/* 
  77.  * diskIO.c --
  78.  *
  79.  *    Routines to do I/O to a raw disk.
  80.  *
  81.  * Copyright (C) 1987 Regents of the University of California
  82.  * All rights reserved.
  83.  * Permission to use, copy, modify, and distribute this
  84.  * software and its documentation for any purpose and without
  85.  * fee is hereby granted, provided that the above copyright
  86.  * notice appear in all copies.  The University of California
  87.  * makes no representations about the suitability of this
  88.  * software for any purpose.  It is provided "as is" without
  89.  * express or implied warranty.
  90.  */
  91.  
  92. #ifndef lint
  93. static char rcsid[] = "$Header: /sprite/src/lib/disk/RCS/diskIO.c,v 1.9 91/09/14 15:17:12 mendel Exp Locker: voelker $ SPRITE (Berkeley)";
  94. #endif not lint
  95.  
  96. #include "disk.h"
  97. #include <stdio.h>
  98. #include <errno.h>
  99. #include <sys/file.h>
  100.  
  101.  
  102. /*
  103.  *----------------------------------------------------------------------
  104.  *
  105.  * Disk_SectorRead --
  106.  *    Read sectors from the disk file at a specified offset.  This combines
  107.  *    an Ioc_Reposition with the read.
  108.  *
  109.  * Results:
  110.  *    0 if could read the sector, -1 if could not.  If couldn't read
  111.  *    the disk then the error is stored in errno.
  112.  *
  113.  * Side effects:
  114.  *    Reposition the disk file's stream pointer and *buffer filled
  115.  *    with data from the disk.
  116.  *
  117.  *----------------------------------------------------------------------
  118.  */
  119. int
  120. Disk_SectorRead(openFileID, firstSector, numSectors, buffer)
  121.     int        openFileID;    /* Handle on raw disk */
  122.     int        firstSector;    /* First sector to read */
  123.     int        numSectors;    /* The number of sectors to read */
  124.     Address    buffer;        /* The buffer to read into */
  125. {
  126.     int amountRead;
  127.  
  128.     if (lseek(openFileID, (long) (firstSector * DEV_BYTES_PER_SECTOR), L_SET) 
  129.     < (long) 0) {
  130.     perror("Disk_SectorRead: lseek failed");
  131.     return(-1);
  132.     }
  133.     amountRead = read(openFileID, buffer, DEV_BYTES_PER_SECTOR * numSectors);
  134.     if (amountRead < 0) {
  135.     perror("Disk_SectorRead: read failed");
  136.     return(-1);
  137.     } else if (amountRead != DEV_BYTES_PER_SECTOR * numSectors) {
  138.     /*
  139.      * short read or EOF
  140.      */
  141.     errno = 0;
  142.     return(-1);
  143.     }
  144.     return(0);
  145. }
  146.  
  147. /*
  148.  *----------------------------------------------------------------------
  149.  *
  150.  * Disk_SectorWrite --
  151.  *    Write sectors to the disk file at a specified offset.  This combines
  152.  *    an Ioc_Reposition with the write.
  153.  *
  154.  * Results:
  155.  *    0 if could write the disk, -1 if could not.  If couldn't read the
  156.  *    disk then the error number is stored in errno.
  157.  *
  158.  * Side effects:
  159.  *    The write.
  160.  *
  161.  *----------------------------------------------------------------------
  162.  */
  163. int
  164. Disk_SectorWrite(openFileID, firstSector, numSectors, buffer)
  165.     int        openFileID;    /* Handle on raw disk */
  166.     int        firstSector;    /* First sector to read */
  167.     int        numSectors;    /* The number of sectors to read */
  168.     Address    buffer;        /* The buffer to read into */
  169. {
  170.     int amountWritten;
  171.  
  172.     if (lseek(openFileID, (long) (firstSector * DEV_BYTES_PER_SECTOR), L_SET) 
  173.     == (long) -1) {
  174.     perror("Disk_SectorWrite: lseek failed");
  175.     fprintf(stderr, "fd = %d, offset = %ld, whence= %d\n",
  176.         openFileID, firstSector * DEV_BYTES_PER_SECTOR, L_SET);
  177.     return(-1);
  178.     }
  179.     amountWritten = write(openFileID, buffer, 
  180.               DEV_BYTES_PER_SECTOR * numSectors);
  181.     if (amountWritten < 0) {
  182.     perror("Disk_SectorWrite: write failed");
  183.     fprintf(stderr, "fd = %d, buffer= 0x%08x, cnt = %d firstSector = %d\n",
  184.         openFileID, buffer, DEV_BYTES_PER_SECTOR * numSectors,
  185.         firstSector);
  186.  
  187.     return(-1);
  188.     } else if (amountWritten != DEV_BYTES_PER_SECTOR * numSectors) {
  189.     /*
  190.      * short write or EOF
  191.      */
  192.     errno = 0;
  193.     return(-1);
  194.     }
  195.     return(0);
  196. }
  197.  
  198.  
  199. /*
  200.  *----------------------------------------------------------------------
  201.  *
  202.  * Disk_BlockRead --
  203.  *    Read blocks to the disk file at a specified block offset.
  204.  *    This has to use the disk geometry information to figure out
  205.  *    what disk sectors correspond to the block.
  206.  *
  207.  * Results:
  208.  *    0 if could read the block, -1 if could not.  If couldn't read the block
  209.  *    the the error is stored in errno.
  210.  *
  211.  * Side effects:
  212.  *    *buffer is filled with the data from the disk.
  213.  *
  214.  *----------------------------------------------------------------------
  215.  */
  216. int
  217. Disk_BlockRead(openFileID, headerPtr, firstBlock, numBlocks, buffer)
  218.     int            openFileID;    /* Handle on raw disk */
  219.     Ofs_DomainHeader    *headerPtr;    /* Domain header with geometry
  220.                      * information */
  221.     int            firstBlock;    /* First block to read */
  222.     int            numBlocks;    /* The number of blocks to read */
  223.     Address        buffer;        /* The buffer to read into */
  224. {
  225.     register Ofs_Geometry *geoPtr;
  226.     register int blockIndex;
  227.     register int cylinder;
  228.     register int rotationalSet;
  229.     register int blockNumber;
  230.     int firstSector;
  231.  
  232.     geoPtr = &headerPtr->geometry;
  233.     for (blockIndex = 0 ; blockIndex < numBlocks ; blockIndex++) {
  234.     blockNumber    = firstBlock + blockIndex;
  235.     cylinder    = blockNumber / geoPtr->blocksPerCylinder;
  236.     if (geoPtr->rotSetsPerCyl > 0) {
  237.         /*
  238.          * Original mapping scheme using rotational sets.
  239.          */
  240.         blockNumber        -= cylinder * geoPtr->blocksPerCylinder;
  241.         rotationalSet    = blockNumber / geoPtr->blocksPerRotSet;
  242.         blockNumber        -= rotationalSet * geoPtr->blocksPerRotSet;
  243.     
  244.         firstSector = geoPtr->sectorsPerTrack * geoPtr->numHeads * 
  245.              cylinder +
  246.              geoPtr->sectorsPerTrack * geoPtr->tracksPerRotSet *
  247.              rotationalSet + geoPtr->blockOffset[blockNumber];
  248.     } else if (geoPtr->rotSetsPerCyl == OFS_SCSI_MAPPING){
  249.         /*
  250.          * New mapping for scsi devices.
  251.          */
  252.         firstSector = geoPtr->sectorsPerTrack * geoPtr->numHeads * 
  253.             cylinder +
  254.             blockNumber * DISK_SECTORS_PER_BLOCK - 
  255.             cylinder * 
  256.             geoPtr->blocksPerCylinder * DISK_SECTORS_PER_BLOCK;
  257.     } else {
  258.         return -1;
  259.     }
  260.     if (Disk_SectorRead(openFileID, firstSector,
  261.                  DISK_SECTORS_PER_BLOCK, buffer) < 0) {
  262.         return(-1);
  263.     }
  264.     buffer += FS_BLOCK_SIZE;
  265.     }
  266.     return(0);
  267. }
  268.  
  269. /*
  270.  *----------------------------------------------------------------------
  271.  *
  272.  * Disk_BadBlockRead --
  273.  *    Read 1 block a sector at a time, returning a bitmap corresponding
  274.  *    to the blocks that were read successfully.
  275.  *    This has to use the disk geometry information to figure out
  276.  *    what disk sectors correspond to the block.
  277.  *
  278.  * Results:
  279.  *    The bitmask of valid sectors is returned.
  280.  *
  281.  * Side effects:
  282.  *    None.
  283.  *
  284.  *----------------------------------------------------------------------
  285.  */
  286. int
  287. Disk_BadBlockRead(openFileID, headerPtr, blockNumber, buffer)
  288.     int openFileID;    /* Handle on raw disk */
  289.     Ofs_DomainHeader *headerPtr;/* Domain header with geometry information */
  290.     int blockNumber;    /* Block to read */
  291.     Address buffer;    /* The buffer to read into */
  292. {
  293.     ReturnStatus status;
  294.     register Ofs_Geometry *geoPtr;
  295.     register int sectorIndex;
  296.     register int cylinder;
  297.     register int rotationalSet;
  298.     int firstSector;
  299.     int valid = 0;        /* Assumes <= 32 sectors/block */
  300.  
  301.     geoPtr = &headerPtr->geometry;
  302.     cylinder    = blockNumber / geoPtr->blocksPerCylinder;
  303.     blockNumber    -= cylinder * geoPtr->blocksPerCylinder;
  304.     rotationalSet    = blockNumber / geoPtr->blocksPerRotSet;
  305.     blockNumber    -= rotationalSet * geoPtr->blocksPerRotSet;
  306.  
  307.     firstSector = geoPtr->sectorsPerTrack * geoPtr->numHeads * cylinder + 
  308.         geoPtr->sectorsPerTrack * geoPtr->tracksPerRotSet * rotationalSet +
  309.         geoPtr->blockOffset[blockNumber];
  310.     for (sectorIndex = 0; sectorIndex < DISK_SECTORS_PER_BLOCK; sectorIndex++) {
  311.     if (Disk_SectorRead(openFileID, firstSector + sectorIndex, 
  312.                 1, buffer) >= 0) {
  313.         valid |= (1 << sectorIndex);
  314.     }
  315.         buffer += DEV_BYTES_PER_SECTOR;
  316.     }
  317.     return(valid);
  318. }
  319.  
  320. /*
  321.  *----------------------------------------------------------------------
  322.  *
  323.  * Disk_BlockWrite --
  324.  *    Write blocks to the disk file at a specified block offset.
  325.  *    This has to use the disk geometry information to figure out
  326.  *    what disk sectors correspond to the block.
  327.  *    Write blocks individually if a hard error occurs during the write
  328.  *    of the entire block.
  329.  *
  330.  *    Note: ignores the error condition otherwise, so if two blocks
  331.  *    are to be written, everything but unwritable sectors will be written
  332.  *    and the error for the unwritable sector(s) would be returned.
  333.  *
  334.  * Results:
  335.  *    0 if could write the block, -1 if could not.  If couldn't write the
  336.  *    block then the error is stored in errno.
  337.  *
  338.  * Side effects:
  339.  *    None.
  340.  *
  341.  *----------------------------------------------------------------------
  342.  */
  343. int
  344. Disk_BlockWrite(openFileID, headerPtr, firstBlock, numBlocks, buffer)
  345.     int            openFileID;    /* Handle on raw disk */
  346.     Ofs_DomainHeader    *headerPtr;    /* Domain header with geometry
  347.                      * information */
  348.     int            firstBlock;    /* First block to read */
  349.     int            numBlocks;    /* The number of blocks to read */
  350.     Address        buffer;        /* The buffer to read into */
  351. {
  352.     register Ofs_Geometry *geoPtr;
  353.     register int blockIndex;    /* Loop counter */
  354.     register int cylinder;    /* Cylinder within domain */
  355.     register int rotationalSet;    /* Rotational Set within cylinder */
  356.     register int blockNumber;    /* Block number within rotational set */
  357.     int firstSector;
  358.  
  359.     geoPtr = &headerPtr->geometry;
  360.     for (blockIndex = 0 ; blockIndex < numBlocks ; blockIndex++) {
  361.     blockNumber    = firstBlock + blockIndex;
  362.     cylinder    = blockNumber / geoPtr->blocksPerCylinder;
  363.     if (geoPtr->rotSetsPerCyl > 0) {
  364.         /*
  365.          * Original mapping scheme using rotational sets.
  366.          */
  367.         blockNumber        -= cylinder * geoPtr->blocksPerCylinder;
  368.         rotationalSet    = blockNumber / geoPtr->blocksPerRotSet;
  369.         blockNumber        -= rotationalSet * geoPtr->blocksPerRotSet;
  370.     
  371.         firstSector = geoPtr->sectorsPerTrack * geoPtr->numHeads * 
  372.              cylinder +
  373.              geoPtr->sectorsPerTrack * geoPtr->tracksPerRotSet *
  374.              rotationalSet + geoPtr->blockOffset[blockNumber];
  375.     } else if (geoPtr->rotSetsPerCyl == OFS_SCSI_MAPPING){
  376.         /*
  377.          * New mapping for scsi devices.
  378.          */
  379.         firstSector = geoPtr->sectorsPerTrack * geoPtr->numHeads * 
  380.             cylinder +
  381.             blockNumber * DISK_SECTORS_PER_BLOCK - 
  382.             cylinder * 
  383.             geoPtr->blocksPerCylinder * DISK_SECTORS_PER_BLOCK;
  384.     } else {
  385.         return -1;
  386.     }
  387.     if (Disk_SectorWrite(openFileID, firstSector,
  388.                  DISK_SECTORS_PER_BLOCK, buffer) < 0) {
  389.         return(-1);
  390.     }
  391.     buffer += FS_BLOCK_SIZE;
  392.     }
  393.     return(0);
  394. }
  395.  
  396. @
  397.  
  398.  
  399. 1.9
  400. log
  401. @Changes to reflect the old Sprite file system name being OFS and the
  402. addition of LFS.
  403. @
  404. text
  405. @d18 1
  406. a18 1
  407. static char rcsid[] = "$Header: /sprite/src/lib/c/disk/RCS/diskIO.c,v 1.8 90/03/16 17:41:15 jhh Exp Locker: mendel $ SPRITE (Berkeley)";
  408. d63 3
  409. a65 2
  410.     fprintf(stderr, "Disk_SectorRead: short read, %d sectors, not %d\n",
  411.                amountRead / DEV_BYTES_PER_SECTOR, numSectors);
  412. d114 3
  413. a116 2
  414.     fprintf(stderr, "Disk_SectorWrite: short write, %d sectors, not %d\n",
  415.                 amountWritten / DEV_BYTES_PER_SECTOR, numSectors);
  416. @
  417.  
  418.  
  419. 1.8
  420. log
  421. @replaced DiskInfo abstraction with Disk_Label
  422. @
  423. text
  424. @d18 1
  425. a18 1
  426. static char rcsid[] = "$Header: /sprite/src/lib/c/disk/RCS/diskIO.c,v 1.7 90/01/31 13:59:59 shirriff Exp Locker: jhh $ SPRITE (Berkeley)";
  427. d142 1
  428. a142 1
  429.     Fsdm_DomainHeader    *headerPtr;    /* Domain header with geometry
  430. d148 1
  431. a148 1
  432.     register Fsdm_Geometry *geoPtr;
  433. d171 1
  434. a171 1
  435.     } else if (geoPtr->rotSetsPerCyl == FSDM_SCSI_MAPPING){
  436. d212 1
  437. a212 1
  438.     Fsdm_DomainHeader *headerPtr;/* Domain header with geometry information */
  439. d217 1
  440. a217 1
  441.     register Fsdm_Geometry *geoPtr;
  442. d269 1
  443. a269 1
  444.     Fsdm_DomainHeader    *headerPtr;    /* Domain header with geometry
  445. d275 1
  446. a275 1
  447.     register Fsdm_Geometry *geoPtr;
  448. d298 1
  449. a298 1
  450.     } else if (geoPtr->rotSetsPerCyl == FSDM_SCSI_MAPPING){
  451. @
  452.  
  453.  
  454. 1.7
  455. log
  456. @Copied change in fsmake to this directory.
  457. This change probably isn't important.
  458. @
  459. text
  460. @d18 1
  461. a18 1
  462. static char rcsid[] = "$Header: /sprite/src/admin/fsinstall/RCS/diskIO.c,v 1.2 89/12/13 14:07:06 rab Exp $ SPRITE (Berkeley)";
  463. d21 1
  464. a21 1
  465. #include "diskUtils.h"
  466. d53 2
  467. a54 1
  468.     if (lseek(openFileID, firstSector * DEV_BYTES_PER_SECTOR, L_SET) < 0) {
  469. d96 2
  470. a97 1
  471.     if (lseek(openFileID, firstSector * DEV_BYTES_PER_SECTOR, L_SET) == -1) {
  472. @
  473.  
  474.  
  475. 1.6
  476. log
  477. @new scsi disk mapping
  478. @
  479. text
  480. @d18 1
  481. a18 1
  482. static char rcsid[] = "$Header: /sprite/src/lib/c/disk/RCS/diskIO.c,v 1.5 89/09/25 12:32:35 jhh Exp Locker: jhh $ SPRITE (Berkeley)";
  483. d95 1
  484. a95 1
  485.     if (lseek(openFileID, firstSector * DEV_BYTES_PER_SECTOR, L_SET) < 0) {
  486. d97 2
  487. d105 4
  488. @
  489.  
  490.  
  491. 1.5
  492. log
  493. @Conforms to new fs module structure
  494. @
  495. text
  496. @d18 1
  497. a18 1
  498. static char rcsid[] = "$Header: /sprite/src/lib/c/disk/RCS/diskIO.c,v 1.4 88/12/05 14:23:13 nelson Exp Locker: jhh $ SPRITE (Berkeley)";
  499. d151 24
  500. a174 9
  501.     blockNumber    -= cylinder * geoPtr->blocksPerCylinder;
  502.     rotationalSet    = blockNumber / geoPtr->blocksPerRotSet;
  503.     blockNumber    -= rotationalSet * geoPtr->blocksPerRotSet;
  504.  
  505.     firstSector = geoPtr->sectorsPerTrack * geoPtr->numHeads *
  506.               cylinder +
  507.               geoPtr->sectorsPerTrack * geoPtr->tracksPerRotSet *
  508.               rotationalSet +
  509.               geoPtr->blockOffset[blockNumber];
  510. d278 24
  511. a301 9
  512.     blockNumber    -= cylinder * geoPtr->blocksPerCylinder;
  513.     rotationalSet    = blockNumber / geoPtr->blocksPerRotSet;
  514.     blockNumber    -= rotationalSet * geoPtr->blocksPerRotSet;
  515.  
  516.     firstSector = geoPtr->sectorsPerTrack * geoPtr->numHeads *
  517.               cylinder +
  518.               geoPtr->sectorsPerTrack * geoPtr->tracksPerRotSet *
  519.               rotationalSet +
  520.               geoPtr->blockOffset[blockNumber];
  521. @
  522.  
  523.  
  524. 1.4
  525. log
  526. @Fixed error in call to lseek in Disk_SectorWrite.
  527. @
  528. text
  529. @d18 1
  530. a18 1
  531. static char rcsid[] = "$Header: /sprite/src/lib/c/disk/RCS/diskIO.c,v 1.3 88/10/27 15:30:47 nelson Exp $ SPRITE (Berkeley)";
  532. d134 1
  533. a134 1
  534.     FsDomainHeader    *headerPtr;    /* Domain header with geometry
  535. d140 1
  536. a140 1
  537.     register FsGeometry *geoPtr;
  538. d189 1
  539. a189 1
  540.     FsDomainHeader *headerPtr;/* Domain header with geometry information */
  541. d194 1
  542. a194 1
  543.     register FsGeometry *geoPtr;
  544. d246 1
  545. a246 1
  546.     FsDomainHeader    *headerPtr;    /* Domain header with geometry
  547. d252 1
  548. a252 1
  549.     register FsGeometry *geoPtr;
  550. @
  551.  
  552.  
  553. 1.3
  554. log
  555. @Ported to the new C library.
  556. @
  557. text
  558. @d18 1
  559. a18 1
  560. static char rcsid[] = "$Header: diskIO.c,v 1.2 88/07/19 11:54:30 douglis Exp $ SPRITE (Berkeley)";
  561. d95 1
  562. a95 1
  563.     if (lseek(openFileID, firstSector * DEV_BYTES_PER_SECTOR, L_SET < 0)) {
  564. @
  565.  
  566.  
  567. 1.2
  568. log
  569. @added Disk_BadBlockRead, to read a sector at a time and return a mask
  570. of the blocks read successfully, and changed BlockWrite to try to
  571. write individual sectors if it gets an error writing the whole thing.
  572. @
  573. text
  574. @d18 1
  575. a18 1
  576. static char rcsid[] = "$Header: diskIO.c,v 1.1 88/06/02 12:54:09 brent Exp $ SPRITE (Berkeley)";
  577. a20 2
  578. #include "sprite.h"
  579. #include "io.h"
  580. d22 3
  581. a24 2
  582. #include "mem.h"
  583. #include "byte.h"
  584. d30 1
  585. a30 1
  586.  * SectorRead --
  587. d35 2
  588. a36 1
  589.  *    The buffer is filled in with read data.
  590. d39 2
  591. a40 1
  592.  *    Reposition the disk file's stream pointer.
  593. d44 6
  594. a49 6
  595. ReturnStatus
  596. SectorRead(openFileID, firstSector, numSectors, buffer)
  597.     int openFileID;    /* Handle on raw disk */
  598.     int firstSector;    /* First sector to read */
  599.     int numSectors;    /* The number of sectors to read */
  600.     Address buffer;    /* The buffer to read into */
  601. a50 2
  602.     ReturnStatus status;
  603.     int oldOffset;        /* Returned from Ioc_Reposition */
  604. d53 3
  605. a55 6
  606.     status = Ioc_Reposition(openFileID, IOC_BASE_ZERO, 
  607.                 firstSector * DEV_BYTES_PER_SECTOR, &oldOffset);
  608.     if (status != SUCCESS) {
  609.     Io_PrintStream(io_StdErr, "SectorRead: Ioc_Reposition failed <%x>\n",
  610.                   status);
  611.     return(status);
  612. d57 4
  613. a60 5
  614.     status = Fs_Read(openFileID, DEV_BYTES_PER_SECTOR * numSectors, buffer,
  615.                 &amountRead);
  616.     if (status != SUCCESS) {
  617.     Io_PrintStream(io_StdErr, "SectorRead: Fs_Read failed <%x>\n", status);
  618.     return(status);
  619. d62 4
  620. a65 3
  621.     Io_PrintStream(io_StdErr,
  622.                "SectorRead: short read, %d sectors, not %d\n",
  623.                amountRead/DEV_BYTES_PER_SECTOR, numSectors);
  624. d67 1
  625. a67 1
  626.     return(SUCCESS);
  627. d73 1
  628. a73 1
  629.  * SectorWrite --
  630. d78 2
  631. a79 1
  632.  *    The return code from the write.
  633. d86 6
  634. a91 6
  635. ReturnStatus
  636. SectorWrite(openFileID, firstSector, numSectors, buffer)
  637.     int openFileID;    /* Handle on raw disk */
  638.     int firstSector;    /* First sector to read */
  639.     int numSectors;    /* The number of sectors to read */
  640.     Address buffer;    /* The buffer to read into */
  641. a92 2
  642.     ReturnStatus status;
  643.     int oldOffset;        /* Returned from Ioc_Reposition */
  644. d95 3
  645. a97 6
  646.     status = Ioc_Reposition(openFileID, IOC_BASE_ZERO, 
  647.                 firstSector * DEV_BYTES_PER_SECTOR, &oldOffset);
  648.     if (status != SUCCESS) {
  649.     Io_PrintStream(io_StdErr, "SectorWrite: Ioc_Reposition failed <%x>\n",
  650.                   status);
  651.     return(status);
  652. d99 5
  653. a103 6
  654.     status = Fs_Write(openFileID, DEV_BYTES_PER_SECTOR * numSectors, buffer,
  655.                 &amountWritten);
  656.     if (status != SUCCESS) {
  657.     Io_PrintStream(io_StdErr,
  658.                "SectorWrite: Fs_Write failed <%x>\n", status);
  659.     return(status);
  660. d105 4
  661. a108 3
  662.     Io_PrintStream(io_StdErr,
  663.                "SectorWrite: short write, %d sectors, not %d\n",
  664.                   amountWritten/DEV_BYTES_PER_SECTOR, numSectors);
  665. d110 1
  666. a110 1
  667.     return(SUCCESS);
  668. d112 1
  669. d117 1
  670. a117 1
  671.  * BlockRead --
  672. d123 2
  673. a124 1
  674.  *    The return code from the read.
  675. d127 1
  676. a127 1
  677.  *    None.
  678. d131 8
  679. a138 7
  680. ReturnStatus
  681. BlockRead(openFileID, headerPtr, firstBlock, numBlocks, buffer)
  682.     int openFileID;    /* Handle on raw disk */
  683.     FsDomainHeader *headerPtr;/* Domain header with geometry information */
  684.     int firstBlock;    /* First block to read */
  685.     int numBlocks;    /* The number of blocks to read */
  686.     Address buffer;    /* The buffer to read into */
  687. a139 1
  688.     ReturnStatus status;
  689. d160 3
  690. a162 4
  691.     status = SectorRead(openFileID, firstSector,
  692.                  SECTORS_PER_BLOCK, buffer);
  693.     if (status != SUCCESS) {
  694.         return(status);
  695. d166 1
  696. a166 1
  697.     return(SUCCESS);
  698. a177 3
  699.  *    Note: this follows what should be the naming convention for all
  700.  *     the routines in this file...
  701.  *
  702. d210 3
  703. a212 3
  704.     for (sectorIndex = 0; sectorIndex < SECTORS_PER_BLOCK; sectorIndex++) {
  705.     status = SectorRead(openFileID, firstSector + sectorIndex, 1, buffer);
  706.     if (status == SUCCESS) {
  707. d223 1
  708. a223 1
  709.  * BlockWrite --
  710. d235 2
  711. a236 1
  712.  *    The return code from the write.
  713. d239 1
  714. a239 1
  715.  *    The write.
  716. d243 8
  717. a250 7
  718. ReturnStatus
  719. BlockWrite(openFileID, headerPtr, firstBlock, numBlocks, buffer)
  720.     int openFileID;    /* Handle on raw disk */
  721.     FsDomainHeader *headerPtr;/* Domain header with geometry information */
  722.     int firstBlock;    /* First block to read */
  723.     int numBlocks;    /* The number of blocks to read */
  724.     Address buffer;    /* The buffer to read into */
  725. a251 2
  726.     ReturnStatus status;
  727.     ReturnStatus realStatus = SUCCESS;
  728. d272 3
  729. a274 18
  730.     status = SectorWrite(openFileID, firstSector,
  731.                  SECTORS_PER_BLOCK, buffer);
  732.     if (status != SUCCESS) {
  733.         /*
  734.          * Try to write each sector individually.
  735.          */
  736.         int sector;
  737.         
  738.         for (sector = 0; sector < SECTORS_PER_BLOCK; sector++) {
  739.         status = SectorWrite(openFileID, firstSector + sector,
  740.                  1, buffer);
  741.         buffer += DEV_BYTES_PER_SECTOR;
  742.         if (status != SUCCESS) {
  743.             realStatus = status;
  744.         }
  745.         }
  746.     } else {
  747.         buffer += FS_BLOCK_SIZE;
  748. d276 1
  749. d278 1
  750. a278 1
  751.     return(realStatus);
  752. @
  753.  
  754.  
  755. 1.1
  756. log
  757. @Initial revision
  758. @
  759. text
  760. @d18 1
  761. a18 1
  762. static char rcsid[] = "$Header: fsDiskUtils.c,v 1.4 87/06/02 11:20:32 nelson Exp $ SPRITE (Berkeley)";
  763. d179 54
  764. d237 2
  765. d240 4
  766. d261 1
  767. d285 15
  768. a299 1
  769.         return(status);
  770. a300 1
  771.     buffer += FS_BLOCK_SIZE;
  772. d302 1
  773. a302 1
  774.     return(SUCCESS);
  775. @
  776.